﻿Namespace HybrisItems.Model

    <Serializable()> _
    Public Class EntireHybrisSystemModel

#Region "Model"

        Private _Relations As Dictionary(Of String, Model.RelationModel)
        Private _Types As Dictionary(Of String, Model.TypeModel)

        Private _ItemTypes As Dictionary(Of String, Model.ItemTypeModel)
        Private _AtomicTypes As Dictionary(Of String, Model.AtomicTypeModel)

        Public Property Relations As Dictionary(Of String, Model.RelationModel)
            Get
                If _Relations Is Nothing Then
                    _Relations = New Dictionary(Of String, Model.RelationModel)
                End If
                Return _Relations
            End Get
            Set(value As Dictionary(Of String, Model.RelationModel))
                _Relations = value
            End Set
        End Property

        Public Property Types As Dictionary(Of String, Model.TypeModel)
            Get
                If _Types Is Nothing Then
                    _Types = New Dictionary(Of String, Model.TypeModel)
                End If
                Return _Types
            End Get
            Set(value As Dictionary(Of String, Model.TypeModel))
                _Types = value
            End Set
        End Property

        Public Property ItemTypes As Dictionary(Of String, Model.ItemTypeModel)
            Get
                If _ItemTypes Is Nothing Then
                    _ItemTypes = New Dictionary(Of String, Model.ItemTypeModel)
                End If
                Return _ItemTypes
            End Get
            Set(value As Dictionary(Of String, Model.ItemTypeModel))
                _ItemTypes = value
            End Set
        End Property

        Public Property AtomicTypes As Dictionary(Of String, Model.AtomicTypeModel)
            Get
                If _AtomicTypes Is Nothing Then
                    _AtomicTypes = New Dictionary(Of String, Model.AtomicTypeModel)
                End If
                Return _AtomicTypes
            End Get
            Set(value As Dictionary(Of String, Model.AtomicTypeModel))
                _AtomicTypes = value
            End Set
        End Property

#End Region

#Region "Methods"

        Public Sub Wire()

            ' Wire relations to ItemTypes
            For Each RelationKey As String In Relations.Keys

                Dim Relation As RelationModel = Relations(RelationKey)

                If Not Relation.IsWired Then
                    Relation.Wire(Me)
                End If

            Next

            ' Wire ItemTypes
            For Each ItemTypeKey As String In ItemTypes.Keys

                Dim ItemType As ItemTypeModel = Types(ItemTypeKey)

                If Not ItemType.IsWired Then
                    ItemType.Wire(Me)
                End If

            Next

        End Sub

#End Region

#Region "Non Current Model Objects"

        ''' <summary>
        ''' The items that have been overwritten due to multiple declaration
        ''' </summary>
        ''' <remarks></remarks>
        Public OverWrittenItems As New HybrisModelBin

        ''' <summary>
        ''' A bin of model objects that can make up Hybris Model, without wiring or any structure 
        ''' </summary>
        ''' <remarks></remarks>
        <Serializable()> _
        Class HybrisModelBin

            Public Relations As New List(Of Model.RelationModel)
            Public Types As New List(Of Model.TypeModel)

        End Class

#End Region

    End Class

End Namespace



